package com.xiaoyu.base.data;

import android.content.Context;

import in.srain.cube.app.init.InitializableSync;

import in.srain.cube.cache.DiskCacheProvider;
import in.srain.cube.cache.DiskFileUtils;

public class CacheData implements InitializableSync {

    private static final String CACHE_DIR = "app-cache";
    private static final int DEFAULT_CACHE_DISK_CACHE_SIZE = 1024 * 10; // 10M
    public static CacheData sInstance;
    private DiskCacheProvider mDiskCacheProvider;

    private CacheData() {
    }

    public static synchronized CacheData getInstance() {
        if (sInstance == null) {
            sInstance = new CacheData();
        }
        return sInstance;
    }

    @Override
    public void initiateSync(Context context) {
        final long size = (long) DEFAULT_CACHE_DISK_CACHE_SIZE * 1024;
        DiskFileUtils.CacheDirInfo cacheDirInfo = DiskFileUtils.getDiskCacheDir(context, CACHE_DIR, DEFAULT_CACHE_DISK_CACHE_SIZE, null);
        mDiskCacheProvider = DiskCacheProvider.createLru(context, cacheDirInfo.path, cacheDirInfo.realSize <= 0 ? size : cacheDirInfo.realSize);
    }

    public DiskCacheProvider getDiskCacheProvider() {
        return mDiskCacheProvider;
    }
}
